use config::{ConfigError, Environment, File};
use serde::Deserialize;

#[derive(Clone, Debug, Deserialize)]
pub struct Config {
    #[serde(default)]
    pub api_key: String,

    #[serde(default)]
    pub secret_key: String,

    #[serde(default)]
    pub base_url: String,

    #[serde(default)]
    pub proxy: Option<String>,

    #[serde(default)]
    pub is_testnet: bool,
}

impl Config {
    /// 返回 WebSocket base URL
    pub fn ws_base_url(&self) -> &'static str {
        if self.is_testnet {
            "wss://fstream.binancefuture.com"
        } else {
            "wss://fstream.binance.com"
        }
    }

    /// 返回 REST base URL（用于外部拼接）
    pub fn rest_base_url(&self) -> &'static str {
        if self.is_testnet {
            "https://testnet.binancefuture.com"
        } else {
            "https://fapi.binance.com"
        }
    }

    /// 构造标准配置
    pub fn new(api_key: String, secret_key: String, is_testnet: bool, proxy: Option<String>) -> Self {
        let base_url = if is_testnet {
            "https://testnet.binancefuture.com".to_string()
        } else {
            "https://fapi.binance.com".to_string()
        };

        Self {
            api_key,
            secret_key,
            base_url,
            proxy,
            is_testnet,
        }
    }
    
}
